package com.xigua.threadSafe;

/**
 * @author LiRongHua
 * @Title: ${file_name}
 * @Package ${package_name}
 * @Description: ${todo}
 * @date 2021/12/2422:43
 */
public class Ticket implements Runnable {

    private  Integer ticket = 100;

    @Override
    public void run() {
        while (true) {
            synchronized ("o") {
                if (ticket > 0) {
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    String name = Thread.currentThread().getName();
                    System.out.println(name + "正在卖" + ticket--);
                }
            }
        }
    }
}
